package net.retorx

import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput
import org.jboss.resteasy.annotations.Form
import javax.ws.rs._
import javax.naming.InitialContext
import java.util.Properties
import javax.mail.internet.{InternetAddress, MimeMessage}
import javax.mail.{Transport, Message, Session}

@Path("/contact")
class ContactService {

	@POST
	@Path("/send")
	def add(@Form contactForm: ContactForm) = {
		val mailProperties = new Properties()
		mailProperties.setProperty("mail.transport.protocol", "smtp")
		mailProperties.setProperty("mail.host", "localhost")

		val session = Session.getDefaultInstance(mailProperties)
		val message = new MimeMessage(session)
		message.setFrom(new InternetAddress("daveclay@daveclay.com"))
		message.setRecipient(Message.RecipientType.TO, new InternetAddress("daveclay+art@gmail.com"))
		message.setSubject("Contact Form Message from daveclay.com/art");
		message.setText("from: " + contactForm.email +  "\nmessage:\n" + contactForm.message)

		//val transport = session.getTransport()
		Transport.send(message)
		print(contactForm)
	}
}